package com.malty.mall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.malty.mall.dao.pms.PmsProductAttributeMapper;
import com.malty.mall.domain.dto.req.pms.PmsAttributeParam;
import com.malty.mall.domain.entity.pms.PmsProductAttribute;
import com.malty.mall.domain.entity.pms.PmsProductAttributeCategory;
import com.malty.mall.service.pms.IPmsProductAttributeCategoryService;
import com.malty.mall.service.pms.IPmsProductAttributeService;
import com.malty.mall.util.PreconditionUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author malty
 */
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PmsProductAttributeServiceImpl extends ServiceImpl<PmsProductAttributeMapper, PmsProductAttribute> implements IPmsProductAttributeService {
    private final IPmsProductAttributeCategoryService productAttributeCategoryService;

    @Override
    public Boolean create(PmsAttributeParam attributeParam) {
        PmsProductAttributeCategory category = productAttributeCategoryService.getById(attributeParam.getCategoryId());
        PreconditionUtils.check(category == null, "分类不存在");
        PmsProductAttribute pmsProductAttribute = new PmsProductAttribute(attributeParam);
        return this.save(pmsProductAttribute);
    }

    @Override
    public Boolean updateCategoryById(PmsAttributeParam attributeParam) {
        PmsProductAttribute pmsProductAttribute = new PmsProductAttribute(attributeParam);
        return this.updateById(pmsProductAttribute);
    }

    @Override
    public PmsAttributeParam queryCateById(Integer id) {
        PmsProductAttribute productAttribute = this.getById(id);
        return new PmsAttributeParam(productAttribute);
    }

    @Override
    public Boolean deleteById(Long id) {
        return this.removeById(id);
    }

    @Override
    public List<PmsAttributeParam> list(Integer pageNum, Integer pageSize, Integer num, Integer size) {
        return null;
    }

    @Override
    public List<PmsAttributeParam> listByProductCategoryId(Integer id) {
        return null;
    }

    @Override
    public List<PmsAttributeParam> listWithAttr() {
        return null;
    }
}
